<!--
 * @name: 
 * @version: 1.1.1
 * @Author: 刘大可
 * @Date: 2022-04-25 15:48:22
 * @LastEditors: 刘大可
 * @LastEditTime: 2022-05-13 19:18:56
-->
<template>
    <view class="tixian" >
        <cu-custom class="bgmains" bgColor="bgmains" :isBack="true">
            <view slot="content">提现</view>
        </cu-custom>
        <view class="header">
            <view class="key">
                我的余额（元）
            </view>
            <view class="val">
                {{userInfo.store_balance||0}}
            </view>
            <view class="key">
                提现最低额度为{{sys.withdraw_min||0}}元
            </view>
        </view>
        <view class="box padding">
            <view class="tit margin-top">提现金额</view>
            <view class="money padding-lr row">
                <view class="key margin-right-sm">￥</view>
                <input class="val" v-model="price" type="digit" placeholder="请输入提现金额" placeholder-class="no" />
            </view>
            <view class="tips margin-top" v-if="is_pay == 1" >
                提现金额将转至微信余额，请注意查收
            </view>
             <view class="padding padding-bottom-sm bg-white margin-top" v-if="is_pay == 0">
                    <view class="title text-grey text-lg">提现方式</view>
                </view>
                <view class="cu-form-group" v-if="is_pay == 0">
                    <view class="title">姓名</view>
                    <input placeholder="输入姓名" name="name" v-model="form.name" />
                </view>
                <view class="cu-form-group" v-if="is_pay == 0">
                    <view class="title">{{ sys.withdraw_tips ? sys.withdraw_tips : '手机号' }}</view>
                    <input placeholder="请输入" name="account" v-model="form.account" />
                </view>
                <view v-if="loading">
                    <view v-if="store.balance>=0" class="submit" @click="formSubmit()">提交申请</view>
                    <view v-else class="submit" style="background: linear-gradient(270deg, #c7c3c3 0%, #908484 100%);">金豆数小于0，不可提现</view>
                </view>
                  
            
        </view>
    </view>
</template>
<script>
// natatorium/regsiter/index.js
var app = getApp();
export default {
    data() {
        return {
            is_pay: 0,
            system: {},

            sys: {
                tixian_word: false
            },
            money: '',
            price:"",
            userInfo: {},
            form: {
                name: '',
                account: ''
            },
			store:{balance:0},
            loading:true
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
        // this.setData({
        // 	is_pay:options.type
        // })
        console.log(options);
        this.getUser();
		this.getStore()
        this.getConfig();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    // onShareAppMessage: function () {},
    methods: {
		getStore() {
		    var that = this;
		    app.globalData.util.request({
		        url: 'ZhBusiness/index',
				method: 'GET',
		        data: {},
		        success(res) {
					// console.log("商家信息返回",res.data.data)
		            that.setData({
		                store: res.data.data.info
		            });
		        }
		    },true);
		},
        moneyinput(e) {
            var text;
            var reg = /^(\.*)(\d+)(\.?)(\d{0,2}).*$/g;

            if (reg.test(e.detail.value)) {
                //正则匹配通过，提取有效文本
                text = e.detail.value.replace(reg, '$2$3$4');
            }

            this.setData({
                money: text
            });
        },

        formSubmit(e) {
            var self = this;
			console.log("提现金额",self.sys)
          
            if (!this.price) {
                app.globalData.util.message('请输入提现金额', '', 'error');
                return false;
            }

            if (Number(this.price) > self.userInfo.store_balance) {
                app.globalData.util.message('余额不足', '', 'error');
                return false;
            }

            if (Number(this.price) < self.sys.withdraw_min) {
                app.globalData.util.message('提现金额不能低于' + self.sys.withdraw_min, '', 'error');
                return false;
            }
			var type = self.is_pay==0?1:2

            if (!this.loading) {
                return false
            }
            this.loading=false
            uni.showLoading({
                title: '正在提交...',
                mask: true
            })
            app.globalData.util.request({
                url: 'UserWithdraw/add',
                data: { ...this.form, openid: uni.getStorageSync('openid'), type:type,is_store:1,price:this.price},
                success(res) {
                    uni.hideLoading();
                    uni.showToast({
                        title: res.data.msg
                    });
                    self.getUser();
                    self.getConfig();
                    setTimeout(function () {
                        uni.navigateBack({});
                    }, 2000);
                }
            },true);
        },

        //获取列表
        getUser() {
            const self = this;
            app.globalData.util.request({
                url: 'WechatUser/view',
                data: {},
                success(res) {
					console.log(res.data.data)
                    self.setData({
                        userInfo: res.data.data
                    });
                }
            },true);
        },

        getConfig() {
            var self = this;
            app.globalData.util.request({
                url: 'Setting/view',
                data: {},
		
                success(res) {
                    self.setData({
                        sys: res.data.data.sys,
                        is_pay: res.data.data.sys.company_pay_switch
                    });
                }
            });
        }

    }
};
</script>

<style lang="scss">
    @import  "./my.scss";
    page{
        background-color:#fff;
    }
</style>
